package com.ymatou.iapi.productimporter.service;

import com.google.common.reflect.TypeToken;
import com.ymatou.iapi.productimporter.parameter.TaskInfo;
import com.ymt.base.YmatouBaseCall;
import com.ymt.core.tool.FormatUtil;
import com.ymttest.utils.EnvSetup;

import java.util.List;

/**
*分页获取导入任务列表Call
*FreeMaker Template自动生成代码
*/
public class GetTaskListCall extends YmatouBaseCall{
	private static String opurl ="task/getTaskList";
	
	public GetTaskListCall() {
		super(EnvSetup.getSystemUrl("productimporter_iapi"),opurl,"POST","JSON");
	}
	@Override
	public void addDefHeader() {
		client.addHeader("Accept","text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}

	public List<TaskInfo> getTaskInfos(){
		String Results=getJsonObject().get("data").getAsJsonObject().get("taskList").getAsJsonArray().toString();
		List<TaskInfo> taskInfos = (List<TaskInfo>) FormatUtil.GSONToObject(Results,new TypeToken<List<TaskInfo>>(){}.getType());
		return taskInfos;
	}
}